<?php
	/*
	file ini digunakan untuk mengontrol login apakah user telah sesuai prosedur masuk aplikasi
	*/
class c_highlight extends CI_Controller {

	function __construct(){
		parent::__construct();
		session_start();
		$this->load->model('m_highlight');
		if(!isset($_SESSION[SESSION_USERID])){
			redirect(base_url());
		}

	}//end Login

	function get_action(){
		$task = isset($_POST['task']) ? @$_POST['task'] : $_GET['task'];
		switch($task){
			case "list":
				$this->highlight_list();
			break;
			case "create":
				$this->highlight_create();
			break;
			case "update":
				$this->highlight_update();
			break;
			case "delete":
				$this->highlight_delete();
			break;
			case "search":
				$this->highlight_search();
			break;
			default:
				echo "{ failure : true }";
			break;
		}
	}

	function index(){
		$data["title"]="highlight";
		$data["content"]=$this->load->view('admin/v_highlight_list',$data,TRUE);
		$this->load->view('admin/v_template',$data);
	}

	function highlight_load(){
		$this->load->view('admin/v_highlight_list');
	}

	function highlight_addedit(){
		$data = array();
		$id = $this->uri->segment(3);
		if($id != false){
			$data['dataDetail'] = $this->m_highlight->getDetail($id);
		}
		$this->load->view('admin/v_highlight_post', $data);
	}

	function highlight_list(){
		$query = $this->input->get('query');
		$pagenum = $_GET['pagenum'];
		$pagesize = $_GET['pagesize'];
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;

		$result=$this->m_highlight->highlight_list($query, $start, $end);
		echo $result;

	}
	function highlight_save(){
		$id = $this->input->post('id');
		$image = $this->input->post('image');
		$isi = $this->input->post('isi');
		$judul = $this->input->post('judul');
		$link = $this->input->post('link');
		$task = $this->input->post('task');

		$image=!preg_match('/upload/i',$image)?'uploads/'.$image:$image;

		$data = array(
			'image'=>$image,
			'isi'=>$isi,
			'judul'=>$judul,
			'link'=>$link,
			'publish'=>'y'
		);

		$params = array(
			'id'=>$id,
			'data'=>$data,
			'task'=>$task
		);
		$result = $this->m_highlight->highlight_save($params);
		echo $result;
	}



	function highlight_delete(){
		$id = $this->input->post('id');
		$id = is_numeric($id) ? $id : $id;
		$result = $this->m_highlight->highlight_delete($id);
		echo $result;
	}

	function highlight_search(){

	}

	function highlight_update(){

	}

	function highlight_create(){

	}

}
?>
